#ifndef UCOMMUNICATION_H
#define UCOMMUNICATION_H
#include <QObject>

#include "cmyudp.h"
#include "CSerialPort/cportthread.h"
#include "cmytcpserver.h"
#include "cmytcpclient.h"

enum ComType {UDPType,TCPSType,TCPCType, SERIALType,UNDEFINE};

class UCommunication:public QObject
{
Q_OBJECT
public:
    UCommunication();
    ~UCommunication();
private:
    CMyTCPClient m_myClient;
    CPortThread m_myPortThread;
    CMyUdp m_myUdp;
    CMyTCPServer m_myTCPS;

    bool m_flagConnected;
    enum ComType m_comType;
public:
    bool IsConnected();
    ComType GetComType();
    void SetComType(enum ComType type);
    void SetComParam(UdpSetStruct udp);
    void SetComParam(TCPSSetStruct tcps);
    void SetComParam(TCPCSetStruct tcpc);
    void SetComParam(SerialStruct serial);
    bool OpenCom();
    void CloseCom();
    int SendData(const char * data, int size, QString address, quint16 port );
    int SendData(const char * data, int size);
private slots:
    void slotTcpClientConnect(QString ip, quint16 port);
    void slotTcpClientDisconnect();
public slots:
    void slotRecvData(char *data, qint64 maxlen, QString host, quint16 port);
signals:
    void sigComData(const char *data, quint64 size);
    void sigUComData(QByteArray data, int size);
    void sigComingConn(QString ip, quint16 port);
    void sigDeleteConn(QString ip, quint16 port);
    void sigTcpClientError(QString error);
    void sigTcpClientConn(QString ip, quint16 port);
    void sigTcpClientDisCon();
};
#endif // UCOMMUNICATION_H
